package org.wang.generalcode.modules.sys.handler;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.wang.generalcode.modules.sys.pojo.enums.IBaseEnum;
import org.wang.generalcode.modules.sys.pojo.enums.MenuTypeEnum;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author wangchong
 */
public class MenuTypeEnumHandler extends BaseTypeHandler<MenuTypeEnum> {
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, MenuTypeEnum menuTypeEnum, JdbcType jdbcType) throws SQLException {
        preparedStatement.setInt(i, menuTypeEnum.getValue());
    }

    @Override
    public MenuTypeEnum getNullableResult(ResultSet resultSet, String s) throws SQLException {
        int code = resultSet.getInt(s);
        return IBaseEnum.getEnumByValue(code, MenuTypeEnum.class);
    }

    @Override
    public MenuTypeEnum getNullableResult(ResultSet resultSet, int i) throws SQLException {
        int code = resultSet.getInt(i);
        return IBaseEnum.getEnumByValue(code, MenuTypeEnum.class);
    }

    @Override
    public MenuTypeEnum getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        int code = callableStatement.getInt(i);
        return IBaseEnum.getEnumByValue(code, MenuTypeEnum.class);
    }
}
